package com.hl.service;

import com.hl.domain.*;
import com.hl.mapper.*;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class CourseDetailService {
    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private CourseVideoMapper courseVideoMapper;

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private CoursemarkMapper coursemarkMapper;

    //展示课程详情
    public Course courseDetail(Long id){
        Course course = courseMapper.selectByPrimaryKey(id);
        return course;
    }

    // 判断课程是否购买
    public Map videoList(Long userId, Long courseId) {
        //查询订单表，查不到就是没有购买
        int i = orderMapper.selectCountByUserAndCourse(userId, courseId);

        List<CourseVideo> courseVideos = courseVideoMapper.selectByCourseId(courseId);
        //System.out.println("课程视频"+courseVideos);
        Map map = new HashMap<>();
        if(courseVideos!=null){
            map.put("video",courseVideos);
        }
        map.put("row",i);
        return map;
    }


    //点击购买时生成订单记录
    public int createOrder(Order order){
        int i = orderMapper.insertSelective(order);
        return i;
    }


    //查询课程下的名师介绍
    public TeacherInfoDTO queryTeacherIntro(Integer courseId){
        TeacherInfoDTO teacherInfoDTO = courseMapper.queryTeacherIntro(courseId);
        return teacherInfoDTO;
    }


    //查询该课程的所有评价
    public List<Coursemark> queryAllMark(Long courseId){
        List<Coursemark> coursemarks = coursemarkMapper.queryAllMark(courseId);
        return coursemarks;
    }

    //交流回复
    public List<CourseQuestion> getCourseQuestions(Integer courseId) {
        List<CourseQuestion> courseQuestions = courseMapper.getCourseQuestions(courseId);
        return courseQuestions;
    }
}
